/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.project.engineering.pages;

import org.apache.shiro.authz.annotation.RequiresGuest;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import pl.project.engineering.data.MailServerConfig;
import pl.project.engineering.entities.AlertEmailAddress;
import pl.project.engineering.services.AppConfig;

/**
 *
 * @author ikrzysiek
 */
public class FirstRunConfiguration {

  
  @Property
  private MailServerConfig mailServerConfig;
  
  @Property
  private AlertEmailAddress emailAddress;
  
  @Inject
  private AppConfig appConfig;
  
  @InjectPage
  private Index index;
  
  Object onActivate() {
    if (appConfig.isLoaded()){
      return index;              
    } else {
      return null;
    }
  }
  
  Object onSuccess(){
    appConfig.setMailServerConfig(mailServerConfig);
    appConfig.getAlertEmailAddressList().addAlertEmailAddress(emailAddress);
    appConfig.SaveConfigFile();
    return index;
  }
}
